<?php
class Dictionary {
	
	const DICT_ENABLED = 'enabled';
	
	const DICT_DISABLED = 'disabled';
	
	public $id = '';
	
	public $name = '';
	
	private $_status = self::DICT_ENABLED;
	
	public function __construct($dictId = null) {
		$this->_model = new DictionaryObjModel();
		if($dictId) {
			$dictionaryData = $this->_model->getDictById($dictId);
			foreach ($dictionaryData as $data) {
				$this->id = $data->id;
				$this->name = $data->name;
				$this->_status = $data->status;
			}
		}
	}

    public function loadByName($dictName) {
        $dictionaryData = $this->_model->getByName($dictName);
		foreach ($dictionaryData as $data) {
			$this->id = $data->id;
			$this->name = $data->name;
			$this->_status = $data->status;
		}
    }

	public function getStatus() {
		return ($this->_status == 1) ? self::DICT_ENABLED : self::DICT_DISABLED;
	}
	
	public function enable() {
		$this->_status = self::DICT_ENABLED; 
	}
	
	public function disable() {
		$this->_status = self::DICT_DISABLED; 
	}
	
	public function save() {
		if(empty($this->id)) {
			$this->_model->save($this);
		}
	}
	
}